package 线程.demo03;

/**
 * @author wql
 * @version 1.0
 * @date 2022/10/31 10:38
 */

public class WqlTicket implements Runnable{
    public int ticket=100;
    private  static  Object lock= new Object();
    @Override
    public void run() {
            while (true){
                synchronized (lock){
                if (ticket>0){
                    System.out.println(Thread.currentThread().getName()+"买了一张票，剩余："+ --ticket);
                }
            }
        }
    }
}
